﻿<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Jessie Hu's Page</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Designer Jessie Hu's page">
    <meta name="author" content="Jewel">
    <!-- Bootstrap -->
    
	<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
	<style>
	    html, body { width:100%; }
	</style>
  </head>
  <body>
    <div style="padding: 200px 50px;">
    <div style="float: left; width:40%;">
        <h3>UID清单</h3>
        <textarea id="needEncodeArea" style="width: 95%; height: 400px;"></textarea>
    </div>
    <div style="float: left; width: 20%; padding-top: 160px;">
        <p style="text-align: center; padding-bottom: 40px;"><input id="encode" type="button" value="encode>>"></p>
        <p style="text-align: center;"><input id="decode" type="button" value="<<decode"></p>
    </div>
    <div style="float: left; width: 40%;">
        <h3>UK清单</h3>
        <textarea id="needDecodeArea" style="width:95%; height:400px;"></textarea>
    </div>

    </div>
    <script src="js/jquery-2.0.3.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script>
        var $needEncodeArea = $('#needEncodeArea'),
            $needDecodeArea = $('#needDecodeArea');
        // 绑定encode按钮的点击事件
        $('#encode').click(function() {
             var values = $needEncodeArea.val();
                 $.post("function.php",{list:values, action:"encode"},function(result){
					if(result==0){
						alert("Soory. Failed.");
						}
					else{
					   $needDecodeArea.val(result);
						}
				});
        });

        // 绑定decode按钮的点击事件
        $('#decode').click(function() {
             var values = $needDecodeArea.val();

                 // 先置空
                $needEncodeArea.val('');
                $.post("function.php",{list:values, action:"decode"},function(result){
					if(result==0){
						alert("Soory. Failed.");
						}
					else{
					   $needEncodeArea.val(result);
						}
				});
        });

        function api_decode_uid($sid) {
            // 非数字，return false
            if(typeof $sid === 'undefined' || !$.isNumeric($sid)) {
                return false;
            }

           	$sid ^= 282335;
   	        $uid = ($sid & 0x00ff0000) << 8;
           	$uid += ($sid & 0x000000ff) << 16;
   	        $uid += (($sid & 0xff000000) >> 16) & 0x0000ff00;
           	$uid += ($sid & 0x0000ff00) >> 8;
   	        return $uid;
        }

        	function api_encode_uid($uid) {
            // 非数字，return false
            if(typeof $uid === 'undefined' || !$.isNumeric($uid)) {
                return false;
            }
                	$sid = ($uid & 0x0000ff00) << 16;
        	        $sid += (($uid & 0xff000000) >> 8) & 0x00ff0000;
               		$sid += ($uid & 0x000000ff) << 8;
        	        $sid += ($uid & 0x00ff0000) >> 16;
                	$sid ^= 282335;
        	        return $sid;
        	}
    </script>
  </body>
</html>